package com.dailywork.basepro.thread.concurrent.concurrent;

import com.common.model.Person;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Phaser类的使用
 *
 * @author think
 */
public class PhaserDemo {

    private final static int THREAD_COUNT = 6;
    private final static ExecutorService service = Executors.newFixedThreadPool(THREAD_COUNT);

    static PartyPhaser partyPhaser = new PartyPhaser();

    public static void main(String[] args) {

        // 批量注册
        partyPhaser.bulkRegister(THREAD_COUNT);

        for (int i = 0; i < THREAD_COUNT; i++) {
            service.submit(new Person("p" + i, partyPhaser));
        }

        // 关闭线程池
        service.shutdown();
    }
}
